
<!--suppress ALL -->
<section class="Hui-article-box">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span>
        分类管理
        <span class="c-gray en">&gt;</span>
        分类列表
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <form action="{:url('search')}" method="get">
            <div class="text-c">
				<span class="select-box inline">
				<select name="pid" class="select">
					<option value="a">全部分类</option>
					{foreach $arr as $val}
                    <option value="{$val.id}" >{$val.catname}</option>
                     {/foreach}
				</select>
				</span>


                <input type="text" name="search" id="" placeholder=" 分类名称" style="width:250px" class="input-text">
                <button name="" id="" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜分类</button>
            </div>
            </form>
            <div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
				<a class="btn btn-primary radius" data-title="添加分类" href="{:url('category/add')}"><i class="Hui-iconfont">&#xe600;</i> 添加分类</a>
				</span>
                <span class="r">共有数据：<strong>54</strong> 条</span>
            </div>
            <!--弹出层的代码-->
            <div id="modal-demo" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content radius">
                        <div class="modal-header">
                            <h3 class="modal-title">对话框标题</h3>
                            <a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
                        </div>
                        <div class="modal-body">
                            <p>对话框内容…</p>
                        </div>
                        <div class="modal-footer">
                            <button class="btn btn-primary">确定</button>
                            <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="mt-20">
                <table class="table table-border table-bordered table-bg table-hover table-sort">
                <!--<table class="layui-table">-->
                    <thead>
                    <tr class="text-c">
                        <th width="25">排序</th>
                        <th width="80">ID</th>

                        <th>标题</th>

                        <th width="60">发布状态</th>
                        <th width="60">添加子分类</th>
                        <th width="120">操作</th>
                    </tr>
                    </thead>
                    <tbody>


                    {:token()}
                    {foreach $data as $val}
                    <tr class="text-c">
                        <td><input type="text" value="{$val.catorder}" name="catorder" style="width: 40px" class=" input-text radius size-S"  id="order" onchange="changeOrder(this,{$val.id})"></td>
                        <td>{$val.id}</td>
                        <td class="text-l"><span class="text-primary"  title="查看" style="font-size: 12px">{php} echo str_repeat('|---',$val['level']) {/php}{$val.catname}</span></td>
                        <td class="td-status"><span class="label label-success radius">{$val.status}</span></td>
                        <td class="td-status"><a href="add/id/{$val.id}" class="btn btn-default">添加子分类</a></td>
                        <td class="f-14 td-manage">
                            <a style="text-decoration:none" class="ml-5" href="{:url('edit',array('id'=>$val['id']))}" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>
                            <a style="text-decoration:none" class="ml-5" onClick="article_del(this,'{$val.id}','/admin/category/delete/{$val.id}')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
                    </tr>


                    {/foreach}
                    </tbody>
                </table>
            </div>
        </article>
    </div>
</section>


<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/static/admin/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/static/admin/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" >
    $('.table-sort').dataTable({
        "aaSorting": [[ 0, "desc" ]],//默认第几个排序
        "bStateSave": true,//状态保存
        "aoColumnDefs": [
            //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
            {"orderable":false,"aTargets":[0,1,2,3,4]}// 不参与排序的列
        ]
    });
    /*进行异步的排序*/
    function changeOrder(obj,id){
        var catorder=$(obj).val();
        var id = id;
        $.ajax({
            'type':'post',//请求的方式
            'data':{'id':id,'catorder':catorder},//附加参数
            'async':true,//异步操作
            'url':"{:url('/admin/category/update_order')}",//服务器端页面
//            'dataType':"json",//响应数据类型
            //接受响应数据的匿名函数
            success:
                function(data){
                    if(data['status']==0){
                        layer.msg(data.msg, {icon: 6});
                    }else{
                        layer.msg(data.msg, function(){
                        });
                    }
                },
            //Ajax 发送失败
            error:
                function(data){
                    layer.msg(data.msg, {icon: 5});
                }
        });
    }

    /*分类-删除*/
    function article_del(obj,id,url){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'get',
                url: url,
                'data':{'id':id},//附加参数
                dataType: 'json',
                success: function(data){
                   //删除成功的提醒
                    if(data['static']==0){
                        $(obj).parents("tr").remove();
                        layer.msg(data.msg,{icon:1,time:1000});
                    }else{
                    //删除不成功的提醒
                        layer.msg(data.msg, function(){
                        });
                    }
                },
                error:function(data) {
                    console.log(data.msg,{icon: 5});
                },
            });
        });
    }
</script>
<!--/请在上方写此页面业务相关的脚本-->
